package com.yunang.officialweb.controller;

import com.yunang.officialweb.common.R;
import com.yunang.officialweb.entity.Servicesproject;
import com.yunang.officialweb.service.ProjectService;
import com.yunang.officialweb.service.TotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/OfficialWebsite")
public class ProjectController {
    @Autowired
    private ProjectService projectService;

    @Autowired
    private TotalService totalService;

    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public R selectAll(){
        return R.ok(projectService.selectAll());
    }

    @RequestMapping(value = "/updateSerPro", method = RequestMethod.PUT)
    public R updateSerPro(@RequestParam int id,
                          @RequestParam(required = false) String name,
                          @RequestParam(required = false) MultipartFile img,
                          @RequestParam(required = false) String desc1,
                          @RequestParam(required = false) String desc2){
        Servicesproject servicesproject = new Servicesproject();
        servicesproject.setId(id);
        servicesproject.setName(name);
        servicesproject.setImg(totalService.savePic(img, "D://YunAng-web//home//serPro//"));
        servicesproject.setDesc1(desc1);
        servicesproject.setDesc2(desc2);
        return R.ok(projectService.updateSerPro(servicesproject));
    }
}
